Search K
Appearance
Appearance
hmall-portal 和 hmall-admin 是前端代码,需要基于 nginx 部署。html 是静态资源目录,我们需要把 hmall-portal 以及 hmall-admin 都复制进去nginx.conf 是 nginx 的配置文件,主要是完成对 html 下的两个静态资源目录做代理将整个 nginx 目录上传到虚拟机的 hmall 目录下。
❯ ls
mysql/ Dockerfile hm-service.jar
❯ tree -L 2 .
.
├── Dockerfile
├── hm-service.jar
├── mysql
│ ├── conf
│ ├── data
│ └── init
└── nginx
├── html
└── nginx.conf
6 directories, 3 files查看本地镜像和容器。
❯ dk images
REPOSITORY TAG IMAGE ID CREATED SIZE
hmall latest af4b5ab8d9fc 2 hours ago 365MB
mysql latest a3b6608898d6 4 weeks ago 596MB
❯ dkpsf -a
CONTAINER ID IMAGE PORTS STATUS NAMES
0912ee2dd460 mysql 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp Up 2 hours mysql
916083d7d274 hmall 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp Up 2 hours hmall运行 nginx 容器,并加入 hmall 网络。
由于需要让 nginx 同时代理 hmall-portal 和 hmall-admin 两套前端资源,因此我们需要暴露两个端口:
18080:对应 hmall-portal18081:对应 hmall-admin❯ docker run -d \
--name nginx \
-p 18080:18080 \
-p 18081:18081 \
-v ./nginx/html:/usr/share/nginx/html \
-v ./nginx/nginx.conf:/etc/nginx/nginx.conf \
--network hmall \
nginx
zsh: correct './nginx/html:/usr/share/nginx/html' to './nginx/html/usr/share/nginx/html' [nyae]? n
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
1f7ce2fa46ab: Pull complete
9b16c94bb686: Pull complete
9a59d19f9c5b: Pull complete
9ea27b074f71: Pull complete
c6edf33e2524: Pull complete
84b1ff10387b: Pull complete
517357831967: Pull complete
Digest: sha256:10d1f5b58f74683ad34eb29287e07dab1e90f10af243f151bb50aa5dbb4d62ee
Status: Downloaded newer image for nginx:latest
8da19e0e98a4d72f382e14238f15befcd3cda6e2a8c37ec5f7c951d35cb3b7b5查看部署的网页。
❯ curl localhost:18080 | head -10
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
<title>黑马商城--首页 2</title>
<link rel="stylesheet" type="text/css" href="css/webbase2.css"/>
<link rel="stylesheet" type="text/css" href="css/pages-index.css"/>
100 60407 100 60407 0 0 75.6M 0 --:--:-- --:--:-- --:--:-- 57.6M
curl: (23) Failed writing body查看 nginx 容器日志。
❯ dk logs nginx
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
172.18.0.1 - - [24/Nov/2023:10:09:43 +0000] "GET / HTTP/1.1" 200 60407 "-" "curl/7.81.0"
172.18.0.1 - - [24/Nov/2023:10:13:14 +0000] "GET / HTTP/1.1" 200 60407 "-" "curl/7.81.0"